package com.stn.zjx.givingtreasure.fragment.main;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter;
import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout;
import com.lcodecore.tkrefreshlayout.header.progresslayout.ProgressLayout;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.adapter.ShopCartItemListAdapter;
import com.stn.zjx.givingtreasure.adapter.ShopItemListAdapter;
import com.stn.zjx.givingtreasure.base.BaseMainFragment;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class MainShopCartFragment extends BaseMainFragment {
    public View rootView;
    @BindView(R.id.msg_iv)
    ImageView msgIv;
    @BindView(R.id.msg_rl)
    RelativeLayout msgRl;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.select_all_Bt)
    CheckBox selectAllBt;
    @BindView(R.id.go_settle_bt)
    TextView goSettleBt;
    @BindView(R.id.now_money_tv)
    TextView nowMoneyTv;
    @BindView(R.id.under)
    LinearLayout under;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.twinkling_refresh)
    TwinklingRefreshLayout twinklingRefresh;
    @BindView(R.id.total_tv)
    TextView totalTv;


    private LinearLayoutManager contentLm;

    private ShopCartItemListAdapter scAapter;

    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @Override
    public View initView(LayoutInflater inflater, ViewGroup container) {
        if (rootView == null) {
            rootView = View.inflate(activity, R.layout.fragment_main_shop_cart, null);
            ButterKnife.bind(this, rootView);
            initView();
        }
        return rootView;
    }

     @SuppressLint("SetTextI18n")
     public void initView(){
         totalTv.setText(getString(R.string.total)+":");
         contentLm=new LinearLayoutManager(activity, OrientationHelper.VERTICAL,false);
         contentLm.setOrientation(OrientationHelper.VERTICAL);
         rv.setLayoutManager(contentLm);
         rv.setAdapter(scAapter=new ShopCartItemListAdapter(activity));
         ProgressLayout headerView = new ProgressLayout(activity);
         headerView.setColorSchemeResources(R.color.colorAccent);
         twinklingRefresh.setHeaderView(headerView);
         twinklingRefresh.setOnRefreshListener(new RefreshListenerAdapter() {
             @Override
             public void onRefresh(final TwinklingRefreshLayout refreshLayout) {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                twinklingRefresh.finishRefreshing();
                            }
                        });
                    }
                }).start();
             }

             @Override
             public void onLoadMore(final TwinklingRefreshLayout refreshLayout) {

             }
         });
     }
    @Override
    public void initData() {
        goSettleBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        List<String> ar=new ArrayList<>();
        ar.add("dsada");
        ar.add("dsad");
        ar.add("dsada");
        ar.add("dsad");
        ar.add("dsada");
        ar.add("dsad");   ar.add("dsada");
        ar.add("dsad");
        ar.add("dsada");
        ar.add("dsad");
        ar.add("dsada");
        ar.add("dsad");   ar.add("dsada");
        ar.add("dsad");   ar.add("dsada");
        ar.add("dsad");   ar.add("dsada");
        ar.add("dsad");
        scAapter.refreshList(ar);
        twinklingRefresh.startRefresh();
    }



}
